home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / EXEC.SWG / 0019_Hiding EXEC commands.pas < prev    next >
Pascal/Delphi Source File  |  1994-02-03  |  2KB  |  104 lines

  1. {
  2.  RG> I am writing a simple program which executes other programs.  I am using
  3.  RG> the function
  4.  
  5.  RG> EXEC(ProgramName,CmdLine)
  6.  
  7.  RG> which is working just fine.  However, I would like to somehow prevent the
  8.  RG> executed program from writing to the screen, rather I just want to display
  9.  RG> in my program something like
  10.  
  11.  RG> Working...
  12.  
  13.  RG> While still maintaining the screen which the program is using for output.
  14.  RG> So my questions is, how would I go about doing this?
  15.  
  16. Try this unit! }
  17.  
  18. unit Redir;
  19.  
  20. interface
  21.  
  22. uses
  23.   Dos;
  24.  
  25. function SetOutput(FileName: PathStr): Boolean;
  26. procedure CancelOutput;
  27.  
  28. implementation
  29.  
  30. const
  31.   OutRedir: Boolean = False;
  32.  
  33. function SetOutput(FileName: PathStr): Boolean;
  34. begin
  35.   FileName:=FileName+#0;
  36.   SetOutput:=False;
  37.   asm
  38.     push  ds
  39.     mov   ax, ss
  40.     mov   ds, ax
  41.     lea   dx, FileName[1]
  42.     mov   ah, 3Ch
  43.     int   21h
  44.     pop   ds
  45.     jnc   @@1
  46.     ret
  47. @@1:
  48.     push  ax
  49.     mov   bx, ax
  50.     mov   cx, Output.FileRec.Handle
  51.     mov   ah, 46h
  52.     int   21h
  53.     mov   ah, 3Eh
  54.     pop   bx
  55.     jnc   @@2
  56.     ret
  57. @@2:
  58.     int   21h
  59.   end;
  60.   OutRedir:=True;
  61.   SetOutput:=True;
  62. end;
  63.  
  64. procedure CancelOutput;
  65. var
  66.   FileName: String[4];
  67. begin
  68.   if not OutRedir then Exit;
  69.   FileName:='CON'#0;
  70.   asm
  71.     push  ds
  72.     mov   ax, ss
  73.     mov   ds, ax
  74.     lea   dx, FileName[1]
  75.     mov   ax, 3D01h
  76.     int   21h
  77.     pop   ds
  78.     jnc   @@1
  79.     ret
  80. @@1:
  81.     push  ax
  82.     mov   bx, ax
  83.     mov   cx, Output.FileRec.Handle
  84.     mov   ah, 46h
  85.     int   21h
  86.     mov   ah, 3Eh
  87.     pop   bx
  88.     int   21h
  89.   end;
  90.   OutRedir:=False;
  91. end;
  92.  
  93. end.
  94.  
  95. ________________
  96.  
  97. Standard output will be changed to FileName. The FileName can be NUL. When your
  98. executed program is using int $10, all is hardly. In your main program use:
  99.  
  100. SetOutput('NUL');
  101. Exec(....);
  102. CancelOutput;
  103.  
  104.